﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Bll;
using SimpComm;
using ViewModel;
using log4net;

namespace UI4._0.Areas.User.Controllers
{
    public class MeController : Controller
    {
        //
        // GET: /User/Home/

        private static readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Login()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Login(UserLogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var msg = AdmInfo.Instance.Login(model.UserName, model.Password);
                if (msg.Success)
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        return Redirect(returnUrl);
                    else
                        return RedirectToAction("Main", "AdmCol");
                }
                else
                {
                    if (logger.IsDebugEnabled)
                        logger.Info("LogOn Error:" + msg.Message + "|Ip:" + this.GetIP());
                    ModelState.AddModelError("", msg.Message + "账号sa,密码sa");
                }
            }
            return View();
        }


    }
}
